package p.ithorns.framework.common.jvmti;

import org.springframework.util.ResourceUtils;

import java.io.FileNotFoundException;

/**
 * ByteCodeEncryptor
 *
 * @author ithorns
 * @version 1.0
 * @date 2022/3/23 16:53
 */
public class ByteCodeEncryptor {

    static {
        try {
            String path = ResourceUtils.getFile("classpath:./").getPath();
            if (path.startsWith("file:")) {
                path = path.substring(5);
            }
            String dllPath;
            String os = System.getProperty("os.name");
            if (os.toLowerCase().startsWith("win")) {
                dllPath = path + "/CodeEncryptor.dll";
            } else {
                dllPath = path + "/CodeEncryptor.so";
            }
            System.load(dllPath);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

    }

    public native static byte[] encrypt(byte[] text);
}
